1195A - Drinks Choosing - CodeForces Solution


greedy math *1000

Please click on ads to support us..

Python Code:

n=int(input().split()[0])
c=[0]*1001
for _ in[0]*n:c[int(input())]+=1
print(n-sum(x%2for x in c)//2)

C++ Code:

// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t, k;
    cin >> t >> k;
     vector<int> arr(t);
     for(auto &it:arr) {cin >> it;}
     vector<int> f(k+1, 0);
for(auto it:arr) {
    f[it]++;
}
int count = 0, rem=0;
for(int i = 1; i<=k; ++i){
    count += (f[i]/2);
    rem += (f[i]%2);
}
cout << (count*2) +((t+1)/2)-count;
    return 0;
}


Comments

Submit
0 Comments
More Questions

1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers